<?php

class Control_Model_Table_News extends Zend_Db_Table_Abstract
{
    protected $_name = 'news';
    
    public function getNewsMainPage()
    {
        $select = $this->select();
        $select->order('id DESC')
               ->where('main=1')
               ->limit('4');
        $UserMenuData = $this->_db->query($select)->fetchAll();
        return $UserMenuData;
    }

        public function getNews()
    {
        $select = $this->select();
        $select->order('id ASC')
               ->limit('25');
        $UserMenuData = $this->_db->query($select)->fetchAll();
        return $UserMenuData;
    }

        public function getAllNews()
    {
        $select = $this->select();
        $select->order('id ASC');
        $UserMenuData = $this->_db->query($select)->fetchAll();
        return $UserMenuData;
    }

        public function addNews($title, $long_text, $link, $date, $main)
    {
        $data = array(
            'title' => $title,
            'long_text' => $long_text,
            'link' => $link,
            'date' => $date,
            'main' => $main
            );
        $this->insert($data);
    }

        public function updateNews($id, $title, $long_text, $link, $date, $main)
    {
        $data = array(
            'title' => $title,
            'long_text' => $long_text,
            'link' => $link,
            'date' => $date,
            'main' => $main
            );
        $this->update($data,'id= '.(int)$id);
    }

        public function deleteData($id)
    {
        $this->delete('id ='.(int)$id);
    }

        public function getDataID($id) {
        $id = (int) $id;
        $row = $this->fetchRow('id =' . $id);
        if (!$row) {
            //           throw new Exception("Count not find row $id");
        } else {
            return $row->toArray();
        }
    }
}

